package net.lzzy.practices.aspects;

import net.lzzy.practices.constants.Messages;
import net.lzzy.practices.entities.User;
import net.lzzy.practices.utils.AspectUtils;
import net.lzzy.practices.utils.AuthUtils;
import net.lzzy.practices.web.models.ApiResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author liaodcc on 2022/5/16 11:56.
 */
@Aspect
@Component
public class AdminControllerAspect {
    @Pointcut("execution(* net.lzzy.practices.web.admin.*.*(..))")
    private void adminAspect(){}


    @Around("adminAspect()")
    public ApiResult checkAdmin(ProceedingJoinPoint joinPoint) throws Throwable {
        String token = AspectUtils.getToken(joinPoint);
        if (AuthUtils.illegalUser(token,new int[]{User.TYPE_ADMIN})){
            return new ApiResult(false, Messages.NO_PERMISSION.toString(),null);
        }
        return (ApiResult) joinPoint.proceed();
    }

}
